using System;
using System.Text;
using System.Collections.Generic;
using Com.ContentRendering.Api.DataEngine;
using NUnit.Framework;
using Com.ContentRendering.Api.DataEngineComponentTest.Helper;
using System.Linq;
using Com.ContentRendering.Api.DataEngine.Exceptions;
using System.Collections;

namespace Com.ContentRendering.Api.DataEngineComponentTest
{
    [TestFixture]
    public class ComponentTest
    {
         [Test]
        public void ValueStringTest()
        {
            string data = "test";

            Assert.AreEqual(
                ValueReflection.Translate(data),
                "test");
        }

        [Test]
        public void ValueIntPositiveTest()
        {
            int data = 100;

            Assert.AreEqual(
                ValueReflection.Translate(data),
                "100");
        }

        [Test]
        public void ValueIntNegativeTest()
        {
            int data = -100;

            Assert.AreEqual(
                ValueReflection.Translate(data),
                "-100");
        }

        [Test]
        public void ValueByteTest()
        {
            byte data = 50;

            Assert.AreEqual(
                ValueReflection.Translate(data),
                "50");
        }

        [Test]
        public void ValueBoolTest()
        {
            bool data = true;

            Assert.AreEqual(
                ValueReflection.Translate(data),
                "True");
        }

        [Test]
        public void ValueStringBuilderTest()
        {
            StringBuilder data = new StringBuilder();

            // write the data to the string builder
            data.Append("test");

            Assert.AreEqual(
                ValueReflection.Translate(data),
                "test");
        }

        [Test]
        public void ChildNullTest()
        {
            object data = null;

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(),
                data,
                "test");

            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildStringLengthTest()
        {
            string data = "test";

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                data,
                "Length");

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, 4);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildBoolTrueTest()
        {
            var data = new { test = true };

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(),
                data,
                "test");

            Assert.AreEqual(enumerator.MoveNext(), true);
        }

        [Test]
        public void ChildBoolFalseTest()
        {
            var data = new { test = false };

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(),
                data,
                "test");

            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildStringNotLengthTest()
        {
            string data = "test";

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                data,
                "NotLength");

            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildEnumeratorStringTest()
        {
            ListHelper<string> data = new ListHelper<string>();

            data.Add("test");

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                data,
                "FetchEnumerator");

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, "test");
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildEnumeratorGenericStringTest()
        {
            ListHelper<string> data = new ListHelper<string>();

            data.Add("test");

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                data,
                "FetchEnumeratorGeneric");

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, "test");
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildArrayStringTest()
        {
            ListHelper<string> data = new ListHelper<string>();

            data.Add("test");

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                data,
                "FetchArray");

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, "test");
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildListStringTest()
        {
            ListHelper<string> data = new ListHelper<string>();

            data.Add("test");

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                data,
                "FetchList");

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, "test");
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildArrayListStringTest()
        {
            ListHelper<string> data = new ListHelper<string>();

            data.Add("test");

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                data,
                "FetchArrayList");

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, "test");
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildEnumeratorIntTest()
        {
            ListHelper<int> data = new ListHelper<int>();

            data.Add(100);

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                data,
                "FetchEnumerator");

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, 100);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildEnumeratorGenericIntTest()
        {
            ListHelper<int> data = new ListHelper<int>();

            data.Add(100);

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                data,
                "FetchEnumeratorGeneric");

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, 100);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildArrayIntTest()
        {
            ListHelper<int> data = new ListHelper<int>();

            data.Add(100);

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                data,
                "FetchArray");

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, 100);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildListIntTest()
        {
            ListHelper<int> data = new ListHelper<int>();

            data.Add(100);

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                data,
                "FetchList");

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, 100);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }
        
        [Test]
        public void ChildArrayListIntTest()
        {
            ListHelper<int> data = new ListHelper<int>();

            data.Add(100);

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                data,
                "FetchArrayList");

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, 100);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildDictionaryStringStringTest()
        {
            Dictionary<string, string> data = new Dictionary<string, string>();

            data.Add("key", "test");

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                data,
                "key");

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, "test");
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildDictionaryStringStringNotFoundTest()
        {
            Dictionary<string, string> data = new Dictionary<string, string>();

            data.Add("key", "value");

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                data,
                "notthekey");

            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildHashtableStringStringTest()
        {
            Hashtable data = new Hashtable();

            data.Add("key", "test");

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                data,
                "key");

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, "test");
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildHashtableStringStringNotFoundTest()
        {
            Hashtable data = new Hashtable();

            data.Add("key", "value");

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                data,
                "notthekey");

            Assert.AreEqual(enumerator.MoveNext(), false);
        }
        
        [Test]
        public void ChildDictionaryByteStringTest()
        {
            Dictionary<string, byte> data = new Dictionary<string, byte>();

            data.Add("key", 5);

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                data,
                "key");

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, 5);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildDictionaryByteStringNotFoundTest()
        {
            Dictionary<string, byte> data = new Dictionary<string, byte>();

            data.Add("key", 5);

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                data,
                "notthekey");

            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildHashtableByteStringTest()
        {
            Hashtable data = new Hashtable();

            data.Add("key", 5);

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                data,
                "key");

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, 5);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildHashtableByteStringNotFoundTest()
        {
            Hashtable data = new Hashtable();

            data.Add("key", 5);

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                data,
                "notthekey");

            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildEnumeratorResetExceptionStringTest()
        {
            // this test was added because some classes do no implement the reset method of the ienumerator class 
            // for example ... the output from a linq statement throw the method not implemented exception

            var results = new { Test = new EnumeratorResetHelper() };

            try
            {
                IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                    new ReflectionCache(), 
                    results, 
                    "Test");
            }
            catch (ResetNotImplementedException)
            {
                return;
            }

            Assert.Fail();
        }

        [Test]
        public void ChildLinqOneTest()
        {
            string[] datas = new string[] { "1", "2", "3" };

            var results = from data in datas select data;

            var resultsWrapper = new { Test = results };

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                resultsWrapper, 
                "Test");

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, "1");
            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, "2");
            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, "3");
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildLinqTwoTest()
        {
            var datas = AnonymousTypeHelper.FetchList(new { One = 0, Two = 0 });

            datas.Add(new { One = 6, Two = 7 });
            datas.Add(new { One = 2, Two = 1 });

            var results = from data in datas select data;

            var resultsWrapper = new { Test = results };

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                resultsWrapper, 
                "Test");

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).One, 6);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).Two, 7);
            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).One, 2);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).Two, 1);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildLinqThreeTest()
        {
            var datas = AnonymousTypeHelper.FetchList(new { One = 0, Two = 0 });

            datas.Add(new { One = 6, Two = 7 });
            datas.Add(new { One = 2, Two = 1 });

            var results = from data in datas select new { One = data.One, Two = data.Two };

            var resultsWrapper = new { Test = results };

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                resultsWrapper, 
                "Test");

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).One, 6);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).Two, 7);
            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).One, 2);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).Two, 1);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void ChildAnonymousTypeTest()
        {
            var results = AnonymousTypeHelper.FetchList(new { One = 0, Two = 0 });

            results.Add(new { One = 6, Two = 7 });
            results.Add(new { One = 2, Two = 1 });

            var resultsWrapper = new { Test = results };

            IEnumerator<object> enumerator = ChildAndSelfRelfectionHelper.Translate(
                new ReflectionCache(), 
                resultsWrapper, 
                "Test");

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).One, 6);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).Two, 7);
            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).One, 2);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).Two, 1);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void SelfNullTest()
        {
            object data = null;

            IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), data);

            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void SelfStringTest()
        {
            string data = "test";
            
            IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), data);

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, "test");
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void SelfBoolTrueTest()
        {
            bool data = true;

            IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), data);

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, string.Empty);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void SelfBoolFalseTest()
        {
            bool data = false;

            IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), data);

            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void SelfEnumeratorStringTest()
        {
            List <string> list = new List<string>();

            list.Add("test");

            IEnumerator data = list.GetEnumerator();

            IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), data);

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, "test");
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void SelfEnumeratorResetExceptionStringTest()
        {
            // this test was added because some classes do no implement the reset method of the ienumerator class 
            // for example ... the output from a linq statement throw the method not implemented exception

            try
            {
                IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), new EnumeratorResetHelper());
            }
            catch (ResetNotImplementedException)
            {
                return;
            }

            Assert.Fail();
        }

        [Test]
        public void SelfEnumeratorGenericStringTest()
        {
            List<string> list = new List<string>();

            list.Add("test");

            IEnumerator<string> data = list.GetEnumerator();

            IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), data);

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, "test");
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void SelfArrayStringTest()
        {
            string[] data = new string[] { "test" };

            IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), data);

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, "test");
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void SelfListStringTest()
        {
            List<string> data = new List<string>();

            data.Add("test");

            IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), data);

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, "test");
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void SelfArrayListStringTest()
        {
            ArrayList data = new ArrayList();

            data.Add("test");

            IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), data);

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, "test");
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void SelfEnumeratorIntTest()
        {
            List<int> list = new List<int>();

            list.Add(100);

            IEnumerator data = list.GetEnumerator();

            IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), data);

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, 100);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void SelfEnumeratorGenericIntTest()
        {
            List<int> list = new List<int>();

            list.Add(100);

            IEnumerator<int> data = list.GetEnumerator();

            IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), data);

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, 100);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void SelfArrayIntTest()
        {
            int[] data = new int[] { 100 };

            IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), data);

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, 100);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void SelfListIntTest()
        {
            List<int> data = new List<int>();

            data.Add(100);

            IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), data);

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, 100);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void SelfArrayListIntTest()
        {
            ArrayList data = new ArrayList();

            data.Add(100);

            IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), data);

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, 100);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void SelfDictionaryStringStringTest()
        {
            Dictionary<string, string> data = new Dictionary<string, string>();

            IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), data);

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, data);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void SelfHashtableStringStringTest()
        {
            Hashtable data = new Hashtable();

            IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), data);

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, data);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void SelfLinqOneTest()
        {
            string[] datas = new string[] { "1", "2", "3" };

            var results = from data in datas select data;
            
            IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), results);

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, "1");
            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, "2");
            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(enumerator.Current, "3");
            Assert.AreEqual(enumerator.MoveNext(), false);
        }
        
        [Test]
        public void SelfLinqTwoTest()
        {
            var datas = AnonymousTypeHelper.FetchList(new { One = 0, Two = 0 });

            datas.Add(new { One = 6, Two = 7 });
            datas.Add(new { One = 2, Two = 1 });

            var results = from data in datas select data;

            IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), results);

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).One, 6);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).Two, 7);
            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).One, 2);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).Two, 1);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }

        [Test]
        public void SelfLinqThreeTest()
        {
            var datas = AnonymousTypeHelper.FetchList(new { One = 0, Two = 0 });

            datas.Add(new { One = 6, Two = 7 });
            datas.Add(new { One = 2, Two = 1 });

            var results = from data in datas select new { One = data.One, Two = data.Two };

            IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), results);

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).One, 6);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).Two, 7);
            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).One, 2);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).Two, 1);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }
        
        [Test]
        public void SelfAnonymousTypeTest()
        {
            var datas = AnonymousTypeHelper.FetchList(new { One = 0, Two = 0 });

            datas.Add(new { One = 6, Two = 7 });
            datas.Add(new { One = 2, Two = 1 });

            IEnumerator<object> enumerator = SelfReflection.Translate(new ReflectionCache(), datas);

            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).One, 6);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).Two, 7);
            Assert.AreEqual(enumerator.MoveNext(), true);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).One, 2);
            Assert.AreEqual(AnonymousTypeHelper.Cast(new { One = 0, Two = 0 }, enumerator.Current).Two, 1);
            Assert.AreEqual(enumerator.MoveNext(), false);
        }
    }
}
